﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AcctruePMS.Bll.Common;
using AcctrueWMS.Foundation.DAL;
using System.Data;
using System.IO;


namespace AcctrueWMS.Web.UploadFiles
{
    public partial class downFile : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string filePath = Request.QueryString["filePath"];
            string sSql = "SELECT fileID, filePath, [fileName], extName FROM sys_attachments WHERE filePath = '" + filePath + "'";
            DataTable allTable = WMSqlExcuter.ExecuteDataTable(sSql);

            if (allTable.Rows.Count <= 0) return;
            string fileName = (string)allTable.Rows[0]["filePath"] + (string)allTable.Rows[0]["extName"];
            string oldFileName = (string)allTable.Rows[0]["fileName"];
            string filename = Server.MapPath(Request.ApplicationPath + System.Configuration.ConfigurationManager.AppSettings["uploadFilePath"].ToString() + "/" + fileName);

            if (!File.Exists(filename))
            {
                Response.Write("您要下载的文件已经不存在！");
                Response.End();
            }

            Response.Clear();
            Response.ContentType = "application/Response.ContentType";
            Response.Charset = "gb2312";
            Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
            Response.AddHeader("Content-Disposition", "attachment;filename=" + Server.UrlPathEncode(oldFileName));
            Response.TransmitFile(filename);

        }
    }
}